<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */
namespace App\Controller;

use App\Exception\ValidatorException;
use App\Request\FooRequest;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\Validation\Contract\ValidatorFactoryInterface;

class IndexController extends BaseController
{
    /**
     * @Inject()
     * @var ValidatorFactoryInterface
     * */
    protected $validatorFactory;

    /**
     * @Inject
     * @var FooRequest
     * */
    protected $foo;
    public function index(RequestInterface $request)
    {
        $user = $this->request->input('user', 'Hyperf');
        $method = $this->request->getMethod();

        $this->validate($request, $this->foo);

        return [
            'method' => $method,
            'message' => "Hello {$user}.",
        ];
    }
}
